<?php
/**
 * RequestHandler class definition
 *  
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MutantVole
 */        
 
/**
 * Base class that provides functionality to add handlers to a Request
 * object for processing. It looks for methods that start with Handle and 
 * matches the rest of the function name against a Request action.
 * @package MutantVole
 * @subpackage Base
 */      
class RequestHandler extends PropertyObject {
	
	/**
     * Look through the class methods to see if any match the Request action.
	 * @param Request $request
	 */  	
	protected function SetupHandlers(Request $request) {
		$methods = get_class_methods(get_class($this));
		
		// strip periods out of action, ie. system.description calls SystemDescription
		$action = str_replace('.', '', $request->action);

		// TODO: replace this with something more clever
		if (is_array($methods)) {
			foreach ($methods as $method) {
				if (preg_match('/^(JSON){0,1}Handle'. $action .'$/i', $method)) {
					$request->AddHandler(array(preg_replace('/^JSON/', '', $method), $this));
				}
			}
		}
	}
}

?>
